﻿namespace WebApplication1
{
    public class HttpBase
    {
        private HttpClient _httpClient;
        private readonly IConfiguration configuration;
        public HttpBase(IConfiguration configuration)
        {
            _httpClient = new HttpClient();
            this.configuration = configuration;
        }
        private List<Uir> Uirs_;

        public List<Uir> Uirs
        {
            get { return  configuration.GetSection("Uir").Get<List<Uir>>(); }
            set { 
                
                Uirs_ = value; 
            
            }
        }

        //工程过程结算反写参数
        public bool GcjsbAuditAfter(string id,string workId)
        {
            object paramsdata1 = new
            {
                jsonrpc = "2.0",
                method = "SettleProject.Gcjsb.AuditAfter",
                @params = new
                {
                    Id = id /*单据Id [String]*/,
                    State = 2 /*状态 [Int32]*/,
                    workId = workId /*作业Id [String]*/,
                    trans = new
                    {
                        TimeOut = 100000
                    } /*作业Id [MQTransClient]*/,
                    isCommit = false /*作业Id [Boolean]*/
                },
                id = 1,
                tags = new
                {
                    userid = "a94220f02a0b-a622-e84f-a0d9-a24be950",
                    username = "王跃",
                    orgid = "a94220dc34ae-a5b7-bb41-a2a1-b590b187",
                    orgname = "四川公路桥梁建设集团有限公司",
                    companycode = "1000",
                    auth_client_id = "test",
                    auth_token = "test",
                    platformid = "1",
                    version = "100.0.0.0"
                }
            };
            string uir = Uirs.Where(o => o.Name == "Project").FirstOrDefault().value;
            var data = _httpClient.PostAsync(uir, new StringContent(System.Text.Json.JsonSerializer.Serialize(paramsdata1), System.Text.Encoding.UTF8, "application/json")).GetAwaiter().GetResult();
            var cont = data.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            return data.StatusCode == System.Net.HttpStatusCode.OK ? true : false;
        }
        //其他结算反写参数
        public bool QtjsAuditAfter(string id, string workId)
        {
            //其他结算反写参数
            object paramsdata2 = new
            {
                jsonrpc = "2.0",
                method = "SettleProject.Qtjs.AuditAfter",
                @params = new
                {
                    Id = id /*单据Id [String]*/,
                    State = 2 /*状态 [Int32]*/,
                    workId = workId /*作业Id [String]*/,
                    isCommit = false /*作业Id [Boolean]*/
                },
                id = 1,
                tags = new
                {
                    userid = "a94220f02a0b-a622-e84f-a0d9-a24be950",
                    username = "王跃",
                    orgid = "a94220dc34ae-a5b7-bb41-a2a1-b590b187",
                    orgname = "四川公路桥梁建设集团有限公司",
                    companycode = "1000",
                    auth_client_id = "test",
                    auth_token = "test",
                    platformid = "1",
                    version = "100.0.0.0"
                }
            };
            string uir= Uirs.Where(o => o.Name == "Project").FirstOrDefault().value;
            var data=  _httpClient.PostAsync(uir, new StringContent(System.Text.Json.JsonSerializer.Serialize(paramsdata2), System.Text.Encoding.UTF8, "application/json")).GetAwaiter().GetResult();
             var cont= data.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            return data.StatusCode== System.Net.HttpStatusCode.OK ? true:false;
        }
    }
}
